<?php

namespace App\Models;


use App\Service\Base\Model;

class SiteInfo extends Model
{

    // 用户管理
    protected $table = 'site_info';

    // 缓存字段，用于搜索绑定的字段
    protected $cacheFields = ['id'];

    // 获取所有的话题信息
    public function getAll($where = [], $order = 'id DESC')
    {
        // 获取缓存
        $bang     = $this->bang;
        $is_cache = $this->is_cache || $bang;
        $args     = compact('where');
        if($is_cache){
            $cacheName = $this->cacheKey('lists', $args);
            $cacheData = $this->cacheClass()->getCache($cacheName);
            if(!empty($cacheData)){
                // 检查是否已经绑定
                if(($cacheData) && (!empty($cacheData))){
                    $this->checkBangList($cacheData, $cacheName);
                }

                return $cacheData;
            }
        }

        // 查询
        if(is_array($order)){
        } else{
            $order = explode(" ", $order);
        }

        $lists  = $this->where($where)->orderby($order[0], $order[1])->get()->toArray();
        $lists  = array_column($lists, null, 'id');
        // 保存为缓存
        if($is_cache){
            $this->addCacheList($lists, $cacheName, $lists, 'list');
        }

        return $lists;
    }

    // 定义验证操作
    public function rules()
    {

        $add = [
        ];

        $edit = [
        ];

        $info = [
        ];


        $rule = [
            //'title'   => 'required',
            'content' => 'required',
            //'status'  => ['in:0,1,2'],
        ];


        $msg = [
            //'status'  => '状态 1-正常 0-禁用',
            'id'      => '编号',
            'title'   => '名称',
            'content' => '内容',
            'itype'   => '类型  html text',
            'ctime'   => '创建时间',
            'mtime'   => '修改时间',
        ];

        return ['rule' => $rule, 'msg' => $msg, 'add' => $add];
    }
}
